import {createStore, combineReducers, compose, applyMiddleware} from 'redux';
import {routerReducer} from 'react-router-redux';
import rootReducer from './reducers';

/*
compose(...functions)
从右到左来组合多个函数。
这是函数式编程中的方法，为了方便，被放到了 Redux 里。
当需要把多个 store 增强器 依次执行的时候，需要用到它。
 */
const finalCreateStore = compose()(createStore);

// rootReducer是根级reducer
const reducer = combineReducers({
	...rootReducer,
	routing: routerReducer
})

export default function configureStore(initialState) {
  // 原先应该是const store = createStore(reducer，initialState);
  // 现在我们通过compose增强操作来实现store的创建
	const store = finalCreateStore(reducer, initialState);
	return store;
}